package com.pxene.dmp.task;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;

import com.pxene.dmp.constant.BaseConstant;
import com.pxene.dmp.constant.FileSuffixTime;

public class InitFSTask implements Tasklet {
	@Autowired
	private FileSystem hadoopFs;

	@Override
	public RepeatStatus execute(StepContribution contribution,
			ChunkContext context) throws Exception {

		Path path = new Path(BaseConstant.HDFS_TEMP_ROOT_DIR
				+ FileSuffixTime.getDatehour() + "/");

		if (hadoopFs.exists(path)) {
			hadoopFs.delete(path, true);
		}

		return RepeatStatus.FINISHED;
	}

}
